//
//  DrawLineViewController.swift
//  swiftAnimation
//
//  Created by zhouLiHuan on 2017/2/16.
//  Copyright © 2017年 zhouLiHuan. All rights reserved.
//

import UIKit

class DrawLineViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        view.backgroundColor = UIColor.white;
        let tempView = UIView(frame:CGRect(x:50,y:100,width:250,height:500));
        let bezierPath = UIBezierPath(ovalIn:tempView.frame);
        
        //椭圆线条
        let shapeLayer = CAShapeLayer();
        shapeLayer.strokeColor = UIColor.purple.cgColor; //线条的颜色
        shapeLayer.fillColor = UIColor.clear.cgColor;  //实心渲染颜色
        shapeLayer.lineWidth = 2.0; //线宽
        shapeLayer.lineJoin = kCALineJoinRound; //设置线条转角的样式
        shapeLayer.lineCap = kCALineCapRound; //设置线条起点和终点的样式
        shapeLayer.path = bezierPath.cgPath;
        view.layer.addSublayer(shapeLayer);
        
        //动画
        let pathAnim = CABasicAnimation(keyPath:"strokeEnd");
        pathAnim.duration = 5.0;
        pathAnim.timingFunction = CAMediaTimingFunction(name:kCAMediaTimingFunctionEaseInEaseOut);
        pathAnim.fromValue = 0;
        pathAnim.toValue = 1;
        pathAnim.autoreverses = true;
        pathAnim.fillMode = kCAFillModeForwards;
        pathAnim.repeatCount = Float.infinity;
        shapeLayer.add(pathAnim, forKey: "strokeEndAnim");
        
           }

}
